const mongoose = require('mongoose');

//启动mongodb：mongod --dbpath e:\mongodata\db
//连接mongo
const DB_URL = 'mongodb://127.0.0.1:27017/editor';
mongoose.connect(DB_URL);

//定义数据文档模型
const models = {
    user: {
        'user': {
            'type': String,
            'require': true
        },
        'pwd': {
            'type': String,
            'require': true
        },
        'type': {
            'type': String,
            'require': true
        },
        'avatar': {
            'type': String
        },
        'desc': {
            'type': String
        },
        'title': {
            'type': String
        },
        'company': {
            'type': String
        },
        'money': {
            'type': String
        }
    },
    'chat': {

    }
}

for(let m in models) {
    mongoose.model(m, new mongoose.Schema(models[m]))
}

module.exports = {
    getModel: function(name) {
        return mongoose.model(name)
    }
}


mongoose.connection.on('connected', function(){
    console.log('数据库连接成功')
})